<?php

use \Welcomescreen\Agavi\Action;
use \Welcomescreen\Objects;

class Backend_Visits_AddAction extends Action\BackendBaseAction {
	public function executeWrite(AgaviWebRequestDataHolder $rd) {
		$ctx = $this->getContext();
		$visitManager = $ctx->getModel('VisitManager');
		
		$visit = new Objects\Visit();
		$visit->setStartDate($rd->getParameter('startDateTime'));
		$visit->setEndDate($rd->getParameter('endDateTime'));
		$visit->setVisitorName($rd->getParameter('visitorName'));
		$visit->setLastEditUser($ctx->getUser()->getUserObject());
		$visit->setTemplateName($rd->getParameter('templateName'));
		$visit->setTemplateData($rd->getParameter('variables', array()));
		
		$visitManager->save($visit);
		
		$this->setAttribute('visit', $visit);
		
		return 'Success';
	}
	
	/**
	 * @return bool
	 */
	public function isSecure() {
		return true;
	}
}

?>